﻿using CocoaAni.Net.WebSockets.Server.Attributes;
using System.Reflection;

namespace CocoaAni.Net.WebSockets.Server.DefineInfos;

public class HandlerDefineInfo
{
    public HandlerDefineInfo(MethodInfo handler, MessageHandlerAttribute? attr = null)
    {
        Name = attr?.Name ?? handler.Name;
        Handler = handler;
        var parameterInfos = handler.GetParameters();
        ArgInfos = new HandlerArgDefineInfo[parameterInfos.Length];
        for (var i = 0; i < parameterInfos.Length; i++)
        {
            var parameterInfo = parameterInfos[i];
            ArgInfos[i] = new HandlerArgDefineInfo(parameterInfo);
        }
    }

    public string Name { get; set; }
    public MethodInfo Handler { get; set; }
    public HandlerArgDefineInfo[] ArgInfos { get; set; }
}